package com.zoshine.zzg.controller;



import com.alibaba.fastjson.JSONObject;
import com.zoshine.zzg.base.BaseResponse;
import com.zoshine.zzg.respons.AppResponse;
import com.zoshine.zzg.service.BankService;
import com.zoshine.zzg.util.HttpClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


/**
 * 调农行接口处理
 * @author mazefei
 * @time 2017年11月8日
 */
@RestController
@RequestMapping(value = "/bank",method = RequestMethod.GET)
public class BankController {

    private BankService bankService;

    @Autowired
    public void setBankService(BankService bankService) {
        this.bankService = bankService;
    }

    /**
     * test
     * @param
     * @return
     */
    @RequestMapping("/test")
    public BaseResponse test(){
        System.out.println("11s");
       /* JSONObject res = HttpClientUtils.httpPost("http://localhost:18080/api/org/listPrison", "");*/
        HttpClientUtil hc=new HttpClientUtil();
        String url="http://10.120.131.19:8080/b_api/jyjgj/transinfo";
        Map<String, String> maps = new HashMap<>();
        maps.put("department", "0103");
        maps.put("prisonerno", "");
        maps.put("date", "20160721");
        String result = null;
        try {
            //url = "http://127.0.0.1:10081/b_api/aoas/openAccount";
            //body="{registerId=399&data="+new String(srcBytes,"utf-8")+"&size=1283}";
            //result=PostSend.HttpPost(url, body);
// result=hc.sendHttpPost(url,maps);
            //result=body.split("\"otherInfo\":")[1].split("},")[0];
            //System.out.println(maps.toString());
            //String postData="cancelType=0&registerId=622&cancelReason=%E8%B6%85%E6%9C%9F%E6%92%A4%E9%94%80";
            //System.out.println(URLDecoder.decode(postData, "utf-8"));
            //System.out.println("解密后:"+new String(srcBytes,"utf-8"));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("发送请求成功"+result);
       // return new AppResponse(res);
        return  AppResponse.OK;
    }

    /**
     * test
     * @param
     * @return
     */
    @RequestMapping("/test2")
    public BaseResponse test2(){

        HttpClientUtil hc=new HttpClientUtil();
        String url="http://localhost:18080/api/goods/listGoods";
        Map<String, Object> maps = new HashMap<>();
        maps.put("goodsName", "sdf");
        String result = null;
        try {
            result=hc.sendHttpPost(url,maps);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("发送请求成功"+result);

       // List<Test> test = JSON.parseArray(result, Test.class);
        JSONObject obj = JSONObject.parseObject(result);
        return  AppResponse.OK;
    }


    /**
     * 调农行接口
     * 1.处理银行卡绑定
     * 2.犯人扣款
     * @param
     * @return
     */
    @RequestMapping("/exec1")
    public BaseResponse exec1(){
        bankService.applyAccount();

        return  AppResponse.OK;
    }

    @RequestMapping("/exec2")
    public BaseResponse exec2(){

        bankService.queryAccount();

        return  AppResponse.OK;
    }

    @RequestMapping("/exec3")
    public BaseResponse exec3(){
        bankService.applyPayment();
        return  AppResponse.OK;
    }
    @RequestMapping("/exec4")
    public BaseResponse exec4(){

        bankService.queryPayment();

        return  AppResponse.OK;
    }
    @RequestMapping("/exec5")
    public BaseResponse exec5(){

        bankService.queryType();

        return  AppResponse.OK;
    }
    @RequestMapping("/exec6")
    public BaseResponse exec6(){

        bankService.queryDepartment();

        return  AppResponse.OK;
    }

    /**
     * 调农行接口
     * 1.处理银行卡绑定
     * 2.犯人扣款
     * @param
     * @return
     */
    @RequestMapping("/autoExec")
    public BaseResponse autoExec(){
       // bankService.queryAccount();
        bankService.queryPayment();
        return  AppResponse.OK;
    }
}
